package org.example.demosql.Controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.example.demosql.ResponseHttps.ResponseData;
import org.example.demosql.SQL.Entity.User;
import org.example.demosql.SQL.Service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Tag(name = "用户添加管理", description = "插入用户信息")
@RequestMapping("/insertUser")
public class InsertUserController {
    @Autowired
    private UserService userService;


    // Post请求
    @Operation(summary = "添加用户")
    @PostMapping("/addUser")
    public ResponseData addUser(@RequestBody User user) {
        boolean result = userService.addUser(user);
        if (result) {
            return new ResponseData("200", "添加成功", true, null);
        } else {
            return new ResponseData("500", "添加失败", false, null);
        }
    }

    @PostMapping("/batchSave")
    @Operation(summary = "批量添加用户")
    public ResponseData batchSave(@RequestBody List<User> userList) {
        boolean result = userService.batchSave(userList);
        if (result) {
            return new ResponseData("200", "添加成功", true, null);
        }else {
            return new ResponseData("500", "添加失败", false, null);
        }
    }


}
